<?php

declare(strict_types=1);
namespace app\api\controller;


use app\api\validate\User;
use app\BaseController;
use think\exception\ValidateException;

class Sms extends BaseController
{
    public function code() : object {
        //获取手机号
        $phoneNumber = input('post.phone_number', '', 'trim');
        $data = [
            'phone_number' => $phoneNumber
        ];
        try {
            (new User())->scene('send_code')->check($data);
        } catch (ValidateException $e) {
            return show(config('status.error'), $e->getError());
        }
        if (\app\common\business\Sms::sendCode($phoneNumber, 4)) {
            return show(config('status.success'), '发送验证码成功');
        } else {
            return show(config('status.error'), '发送验证码失败');
        }
    }
}